import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "../views/Home/Home.vue"
import SongMore from "../views/More/SongMore.vue"
import RankingMore from "../views/More/RankingMore.vue"
import MvMore from "../views/More/MvMore.vue"
import SingerMore from "../views/More/SingerMore.vue"
import MyMusic from "../views/More/MyMusic.vue"
import SongDetail from "../views/Detail/SongDetail.vue"
import SingerDetail from "../views/Detail/SingerDetail.vue"
import MvDetail from "../views/Detail/MvDetail.vue"
import Chinese from "../views/More/children/Chinese.vue"
import America from "../views/More/children/America.vue"
import Japanese from "../views/More/children/Japanese.vue"
import Korean from "../views/More/children/Korean.vue"
import AllSong from "../views/More/children/AllSong.vue"
import Allsinger from "../views/More/singerChildren/Allsinger.vue"
import Mansinger from "../views/More/singerChildren/Mansinger.vue"
import Womansinger from "../views/More/singerChildren/Womansinger.vue"
import HotRanking from "../views/More/rankingchildren/HotRanking.vue"
import NewRanking from "../views/More/rankingchildren/NewRanking.vue"
import OriginalRanking from "../views/More/rankingchildren/OriginalRanking.vue"
import SoarRanking from "../views/More/rankingchildren/SoarRanking.vue"
import HotWorks from '../views/Detail/singerchildren/HotWorks.vue'
import RelevantMv from "../views/Detail/singerchildren/RelevantMv.vue"
import Artist from "../views/Detail/singerchildren/Artist.vue"
import Search from "../views/Detail/Search.vue"
import Play from "../views/paly"
import Login from "../views/Login/Login.vue"
import Register from "../views/Login/Register.vue"
Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:"/login"
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      isNav: true,
      isSer:true
    },
  },
  {
    path: '/songmore',
    name: 'SongMore',
    component: SongMore,
    meta: {
      isNav: true,
      isSer:true
    },
    redirect:"/songmore/allsong",
    children:[
      {
        path:"/songmore/chinese",
        component:Chinese,
        meta: {
          isNav: true,
          isSer:true
        },
      },{
        path:"/songmore/america",
        component:America,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path:'/songmore/Japanese',
        component:Japanese,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path:'/songmore/korean',
        component:Korean,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path:'/songmore/allsong',
        component:AllSong,
        meta: {
          isNav: true,
          isSer:true
        },
      }
    ]
  },
  {
    path: '/rankingmore',
    name: 'RankingMore',
    component: RankingMore,
    meta: {
      isNav: true,
      isSer:true
    },
    redirect:'/rankingmore/hotranking',
    children:[
      {
        path: '/rankingmore/hotranking',
        component:HotRanking,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path: '/rankingmore/newranking',
        component:NewRanking,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path: '/rankingmore/originalranking',
        component:OriginalRanking,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path: '/rankingmore/soarranking',
        component:SoarRanking,
        meta: {
          isNav: true,
          isSer:true
        },
      }
    ]
  },
  {
    path: '/mvmore',
    name: 'MvMore ',
    component: MvMore ,
    meta: {
      isNav: true,
      isSer:true
    },
  },
  {
    path: '/singerMore',
    name: 'SingerMore ',
    component: SingerMore,
    meta: {
      isNav: true,
      isSer:true
    },
    redirect:'/singerMore/allsinger',
    children:[
      {
        path:'/singerMore/allsinger',
        component:Allsinger,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path:'/singerMore/mansinger',
        component:Mansinger,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path:'/singerMore/womansinger',
        component:Womansinger,
        meta: {
          isNav: true,
          isSer:true
        },
      }
    ]
  },
  {
    path: '/mymusic',
    name: 'MyMusic ',
    component: MyMusic,
    meta: {
      isNav: true,
      isSer:true
    },
  },
  {
    path: '/songdetail',
    name: ' SongDetail',
    component: SongDetail,
    meta: {
      isNav: true,
      isSer:true
    },
  },
  {
    path:'/mvdetail',
    component:MvDetail,
    meta: {
      isNav: true
    },
  },
  {
    path:"/singerdetail",
    component:SingerDetail,
    redirect:"/singerdetail/hotworks",
    meta: {
      isNav: true,
      isSer:true
    },
    children:[
      {
        path:"/singerdetail/hotworks",
        component:HotWorks,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path:"/singerdetail/relevantmv",
        component:RelevantMv,
        meta: {
          isNav: true,
          isSer:true
        },
      },
      {
        path:"/singerdetail/artist",
        component:Artist,
        meta: {
          isNav: true,
          isSer:true
        },
      }
    ]
  },
  {
    path:'/play',
    component:Play,
    meta: {
      isNav: true
    },
  },
  {
    path:'/login',
    component:Login
  },
  {
    path:'/register',
    component:Register
  },
  {
    path:"/search",
    component:Search,
    meta: {
      isNav: true,
      isSer:true
    },
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
var vm = new Vue();
router.beforeEach((to,from,next)=>{
  console.log(vm.$cookie.get("token"));
  var isLogin = vm.$cookie.get("token")
  if(to.path == "/login" || to.path == '/register'){
    // 1.在登录页面 如果cookie显示登录了直接进入home页面 ， 如果没有登录，正常执行login页面的逻辑
    if(isLogin){
      router.push("/home")
    }else{
      next()
    }
  }else{
    // 2.在其他页面 如果登录正常显示；没有登录则停留在login页面
    if(isLogin){
      next()
    }else{
      router.push("/login")
    }
  }
})
export default router
